package tms.persistence.profile;

import tms.model.profile.UserProfileEntity;
import tms.persistence.ProviderBase;

import javax.ejb.Local;
import javax.ejb.Stateless;
import java.util.List;

@Local
@Stateless
public class ProfileProvider extends ProviderBase {

    public void updateProfile(UserProfileEntity profile) {
        getEntityManager().merge(profile);
    }

    @SuppressWarnings("unchecked")
    public List<UserProfileEntity> getAllByJabberId(String jabberId) {
        return (List<UserProfileEntity>)getEntityManager().
                createNamedQuery("UserProfileEntity.getByJabberId").
                setParameter("jabberId", jabberId).
                getResultList();
    }

    public UserProfileEntity getProfile(Integer id) {
        return getEntityManager().find(UserProfileEntity.class, id);
    }

    @SuppressWarnings("unchecked")
    public List<UserProfileEntity> getAllProfiles() {
        return getEntityManager().createNamedQuery("UserProfileEntity.getAll").getResultList();
    }
}
